//
//  MainViewController.swift
//  SineWeibo
//
//  Created by keshuaiguo on 16/1/14.
//  Copyright © 2016年 keshuaiguo. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    //MARK:加号按钮的监听事件
  @objc private func plusBtnDidClick() {
    
        print(__FUNCTION__)
    
    }

  override func viewDidLoad() {
        super.viewDidLoad()
      //使用KVC 修改tabBar
        let mainTabBar = MainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)

        addChildViewControllers()
    }
    
   private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
         addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
        
    }
    
    //添加子视图控制器
   private func addChildViewController(vc:UIViewController,imageName:String,title:String) {
        
        //设置文字
        vc.title = title
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        
        self.tabBar.tintColor = UIColor.orangeColor()
        //设置选中图片
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//       vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        //导航控制器
        let nav = UINavigationController(rootViewController: vc)
        //添加子视图控制器
        addChildViewController(nav)
    }
    
}
